#pragma once
#include <vector>

class Settings;
class Modulator;
class Carrier;
class Vocoder;

/*
A typical 'driver' for vocoding.
Runs the loop that calls modulator for the next sample, asks carrier to create an accompanying sample, and then asks vocoder to vocode those.
*/
class VocoderDriver
{
public:
	VocoderDriver(void);
	~VocoderDriver(void);

	/*
	Create necessary buffers and store pointer to modulator, carrier and vocoder implementations.
	*/
	void Initialize(Settings* settings, Modulator* modulator, Carrier* carrier, Vocoder* vocoder, int windowLength);

	/*
	Start the loop and run it until another thread calls Stop, or until modulator->NextModulatorSample returns false
	*/
	void Start();

	/*
	Stop the currently running loop (must be called from another thread).
	Does nothing if the loop is not running.
	*/
	void Stop();

private:
	Settings* settings;
	Modulator* modulator;
	Carrier* carrier;
	Vocoder* vocoder;
	int windowLength;
	std::vector<short> modulatorOutput;
	std::vector<short> carrierOutput;
	std::vector<short> vocoderOutput;
	bool vocoding;
};
